﻿using System;
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{

    class Solidorbrazedturningtoolno1straightdesign
    {
        public static void _Solidorbrazedturningtoolno1straightdesign(Dictionary<string, Object> data)//细柄丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            double scale = 2; //放大系数

            double oal = 42.72;
            double b = 8.57;
            double h = 8.57;
            double l = 7.26;
            double lpr = 19.92;
            double kapr = 69;
            double s = 1.37;

            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X + oal, v1.Y);
            Vector2 v3 = new Vector2(v2.X - h * Math.Tan(26 * pi / 180), v1.Y - h);
            Vector2 v4 = new Vector2(v1.X, v3.Y);
            Vector2 v5 = new Vector2(v2.X - l * Math.Sin(kapr * pi / 180), v2.Y);
            Vector2 v6 = new Vector2(v5.X, v5.Y - s);
            Vector2 v7 = new Vector2(v2.X - s * Math.Tan(26 * pi / 180), v6.Y);
            Vector2 v8 = new Vector2(v2.X - oal / 5.974, v2.Y);
            Vector2 v9 = new Vector2(v8.X - oal / 38.486, v4.Y);
            Vector2 v22 = new Vector2(v2.X - lpr, v1.Y);
            Vector2 v24 = new Vector2(v2.X + h, v2.Y);

            Vector2 v10 = new Vector2(v4.X, v4.Y - oal / 3.045);
            Vector2 v11 = new Vector2(v10.X, v10.Y - b);
            Vector2 v12 = new Vector2(v8.X, v11.Y);
            Vector2 v13 = new Vector2(v2.X, v12.Y + (v2.X - v8.X) / Math.Tan(kapr * pi / 180));
            Vector2 v14 = fun.Polar(v13, (-kapr - 90) * pi / 180, l);
            Vector2 v15 = new Vector2(v13.X - (v10.Y - v13.Y) * Math.Tan((90 - kapr) * pi / 180), v10.Y);
            Vector2 v16 = new Vector2(v14.X - (v15.Y - v14.Y) * Math.Tan(20 * pi / 180), v15.Y);
            Vector2 v17 = new Vector2(v12.X - oal / 18.335, v12.Y);
            Vector2 v18 = new Vector2(v17.X - b * Math.Tan(20 * pi / 180), v15.Y);
            Vector2 v19 = new Vector2(v14.X - (b / 3.128) * Math.Tan(20 * pi / 180), v14.Y + b / 3.128);
            Vector2 v20 = new Vector2(v19.X + l / 3.507, v19.Y + b / 3.678);
            Vector2 v21 = new Vector2(v13.X - (b / 2.075) * Math.Tan((90 - kapr) * pi / 180), v13.Y + b / 2.075);
            Vector2 v23 = new Vector2(v22.X, v10.Y - b / 2);
            Vector2 v25 = new Vector2(v18.X + (v17.X - v18.X) / 2, v23.Y);



            //作图
            LwPolyline line1 = new LwPolyline();
            line1.Vertexes.Add(new LwPolylineVertex(v5));
            line1.Vertexes.Add(new LwPolylineVertex(v6));
            line1.Vertexes.Add(new LwPolylineVertex(v7));
            line1.Vertexes.Add(new LwPolylineVertex(v2));
            line1.Vertexes.Add(new LwPolylineVertex(v1));
            line1.Vertexes.Add(new LwPolylineVertex(v4));
            line1.Vertexes.Add(new LwPolylineVertex(v3));
            line1.Vertexes.Add(new LwPolylineVertex(v2));
            line1.Vertexes.Add(new LwPolylineVertex(v8));
            line1.Vertexes.Add(new LwPolylineVertex(v9));
            fun.PolyFill(dxf, line1, 0.2, contour);

            LwPolyline line2 = new LwPolyline();
            line2.Vertexes.Add(new LwPolylineVertex(v14));
            line2.Vertexes.Add(new LwPolylineVertex(v16));
            line2.Vertexes.Add(new LwPolylineVertex(v15));
            line2.Vertexes.Add(new LwPolylineVertex(v13));
            line2.Vertexes.Add(new LwPolylineVertex(v12));
            line2.Vertexes.Add(new LwPolylineVertex(v11));
            line2.Vertexes.Add(new LwPolylineVertex(v10));
            line2.Vertexes.Add(new LwPolylineVertex(v16));
            line2.Vertexes.Add(new LwPolylineVertex(v18));
            line2.Vertexes.Add(new LwPolylineVertex(v17));
            fun.PolyFill(dxf, line2, 0.2, contour);

            LwPolyline line3 = new LwPolyline();
            line3.Vertexes.Add(new LwPolylineVertex(v19));
            line3.Vertexes.Add(new LwPolylineVertex(v20));
            line3.Vertexes.Add(new LwPolylineVertex(v21));
            line3.Vertexes[0].Bulge = Math.Tan(-47 * pi / 180 / 4);
            fun.PolyFill(dxf, line3, 0.2, contour);

            LwPolyline line4 = new LwPolyline();
            line4.Vertexes.Add(new LwPolylineVertex(v2));
            line4.Vertexes.Add(new LwPolylineVertex(v24));
            fun.PolyFill(dxf, line4, 0.02, dimensioning);


            //坐标系
            fun.Axis(dxf, v4, 90, 180, "Y", "Z", "PCS", 0.5, 2, 0);

            fun.Axis(dxf, v10, -90, 180, "X", "Z", "PCS", 0.5, 2, 0);

            fun.Axis(dxf, v22, 90, 180, "Y", "Z", "MCS", 0.5, 2, 0);

            fun.Axis(dxf, v23, -90, 180, "X", "Z", "MCS", 0.5, 2, 0);




            //标注

            double height = 2;
            double arrowsize = 2;
            double exline = 2;



            fun.dimrot1(dxf, v1, v4, 90, h, 1, height, arrowsize, exline, "H", "", "");

            fun.dimrot1(dxf, v2, v3, -90,h, 1, height, arrowsize, exline, "HF", "", "");

            fun.jt(dxf, new Vector2(v24.X - 0.3, v24.Y), 90, 9, height, "HTA");

            //2
            fun.dimrot1(dxf, v10, v11, 90, h, 1, height, arrowsize, exline, "B", "", "");

            fun.dimrot1(dxf, v18, v25, 90, h * 2, 1, height, arrowsize, exline, "=", "", "");

            fun.dimrot1(dxf, new Vector2(v18.X, v11.Y), v25, 90, h * 2, 1, height, arrowsize, exline, "=", "", "");

            fun.dimrot1(dxf, v25, v13, -90, h + (v2.X + v3.X) / 2 - (v13.X + v25.X) / 2, 1, height, arrowsize, exline, "WTA", "", "");

            fun.dimrot1(dxf, v13, v15, -90, h * 1.5, 1, height, arrowsize, exline, "WF", "", "");

            fun.dimrot1(dxf, v23, v13, 180, h * 2, 1, height, arrowsize, exline, "LPR,LTA", "", "");

            fun.dimrot1(dxf, v11, v13, 180, h * 3, 1, height, arrowsize, exline, "OAL,LF", "", "");

            fun.jdbz2(dxf, new Line(v13, fun.Polar(v13, (-kapr - 90) * pi / 180, 0.1)), new Line(v13, fun.Polar(v13, -90 * pi / 180, 0.1)), l / 1, height, arrowsize, exline, "KAPR", "", "");

            fun.jt(dxf, new Vector2(v10.X + oal / 4, v10.Y), 135, 9, height, "CCMS");




            //定义格式，路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);


        }

    }
}